﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace Chunker
{
    public static class Util
    {
        public static string GetHash( byte[] buffer )
        {
            SHA1 sha = new SHA1CryptoServiceProvider();
            return BitConverter.ToString( sha.ComputeHash( buffer ) ).Replace( "-", "" );
        }

        public static string GetHash( string filePath )
        {
            using ( HashAlgorithm hashAlg = new SHA1Managed() ) {
                using ( Stream file = new FileStream( filePath, FileMode.Open, FileAccess.Read ) ) {
                    byte[] hash = hashAlg.ComputeHash( file );
                    return BitConverter.ToString( hash ).Replace( "-", "" );
                }
            }
        }

        public static string[] GetFiles( string path, string filter, bool allDirectories )
        {
            return Directory.GetFiles( path, filter, allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly );
        }
    }
}
